<!-- 搜索表单 -->
<template>
    <el-card shadow="never" >
      <el-form
        label-width="77px"
        class="ele-form-search"
        @keyup.enter.native="search"
        @submit.native.prevent
      >
        <el-row :gutter="24">
          <el-col :lg="6" :md="24">
            <el-form-item label="单据编号:">
              <el-input clearable v-model="where.billNo" placeholder="请输入单据编号" />
            </el-form-item>
          </el-col>
          <el-col :lg="6" :md="24">
            <el-form-item label="单据类型:">
              <el-select v-model="where.billType" clearable placeholder="请选择单据类型" style="width: 100%;">
                <el-option v-for="(item, index) in stockBillType" :key="index" :label="item.Value" :value="item.Key" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :md="24">
            <el-form-item label="数量:">
              <el-input clearable v-model="where.qty" placeholder="请输入数量" />
            </el-form-item>
          </el-col>
          <el-col :lg="4" :md="24">
            <div class="ele-form-actions">
              <el-button
                type="primary"
                icon="el-icon-search"
                class="ele-btn-icon"
                @click="search"
              >
                查询
              </el-button>
              <el-button @click="reset">重置</el-button>
            </div>
          </el-col>
          <el-col :md="24" :sm="24" v-if="!searchExpand">
            <div class="expandcollect">
              <el-link type="primary" :underline="false" @click="toggleExpand">
                <template>
                  <i class="el-icon-arrow-down">展开更多</i>
                </template>
              </el-link>
            </div>
          </el-col>
          <el-col :lg="6" :md="24" v-if="searchExpand">
            <el-form-item label="单据日期:">
              <el-date-picker v-model="where.billDate" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="daterange"
                  range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 300px;" >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :md="24" v-if="searchExpand">
            <el-form-item label="过账日期:">
              <el-date-picker v-model="where.peddingDate" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="daterange"
                  range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 300px;" >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :md="24" :sm="24" v-if="searchExpand">
            <div class="expandcollect">
              <el-link type="primary" :underline="false" @click="toggleExpand">
                <template v-if="searchExpand">
                  <i class="el-icon-arrow-up">收起</i>
                </template>
              </el-link>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    </template>
    
    <script>
      const DEFAULT_WHERE = {
        qty:'',
        billNo: '',  //关键字
        billType:'',
        peddingDate:'',
        billDate:'',
      };

      import { QueryStockBillTypeEnum } from '@/api/enummanger';
      export default {
        name: 'StockLogSearch',
        data() {
          return {
            // 表单数据
            stockBillType:[],
            searchExpand:false,
            where: { ...DEFAULT_WHERE },
          };
        },
        //初始化数据
        created(){
          this.queryStatusEnums();
        },
        methods: {
    
          /* 搜索 */
          search() {
            let params = {
              pageindex: 1,
              conditions: {},
              orderBys: [{ sort: "createDate", order: 1, }],
            };
    
            //关键字查询
            if(this.where.qty){
              params.conditions.qty = this.where.qty;
            }

            //供应商查询
            if(this.where.billNo){
              params.conditions.billNo = this.where.billNo;
            }

            //仓库查询
            if(this.where.billType){
              params.conditions.billType = this.where.billType;
            }

            //制单日期
            if(this.where.billDate){
              params.conditions.billStartDate = this.where.billDate[0] + " 00:00:00";
              params.conditions.billEndDate =  this.where.billDate[1] + " 23:59:59";
            }

            //制单日期
            if(this.where.peddingDate){
              params.conditions.peddingStartDate = this.where.peddingDate[0] + " 00:00:00";
              params.conditions.peddingEndDate =  this.where.peddingDate[1] + " 23:59:59";
            }
    
            this.$emit('search', params);
          },
          /*  重置 */
          reset() {
            this.where = { ...DEFAULT_WHERE };
            this.search();
          },
    
          /* 系统状态 */
          async queryStatusEnums(){
            this.stockBillType = [];
            let sysEnums = await QueryStockBillTypeEnum();
            sysEnums.map(e=>{
              this.stockBillType.push({Key:e.Key,Value:e.Value});
            });
          },

          /* 搜索展开/收起 */
          toggleExpand() {
            this.searchExpand = !this.searchExpand;
          },
        }
      };
    </script>
    